package com.qiangesoft.im.util;

import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * id工具类
 *
 * @author qiangesoft
 */
public class IdSplitUtil {

    /**
     * ids to idList
     *
     * @param ids
     * @return
     */
    public static List<Long> strToList(String ids) {
        List<Long> idList = new ArrayList<>();
        if (ids == null || ids.length() == 0) {
            return idList;
        }
        String[] split = ids.split(",");
        for (String id : split) {
            idList.add(Long.parseLong(id));
        }
        return idList;
    }

    /**
     * idList to ids
     *
     * @param idList
     * @return
     */
    public static String listToStr(List<Long> idList) {
        return StringUtils.join(idList, ",");
    }

    /**
     * ids to idList
     *
     * @param ids
     * @return
     */
    public static List<String> strToSList(String ids) {
        List<String> idList = new ArrayList<>();
        if (ids == null || ids.length() == 0) {
            return idList;
        }
        String[] split = ids.split(",");
        for (String id : split) {
            idList.add(id);
        }
        return idList;
    }

    /**
     * idList to ids
     *
     * @param idList
     * @return
     */
    public static String slistToStr(List<String> idList) {
        return StringUtils.join(idList, ",");
    }
}
